#!/user/bin/env python3
# -*- coding: utf-8 -*-
"""
--------------------------------------
    Author:     JiChao_Song
    Date  :     2021/11/28 15:33
    Desc  :
--------------------------------------
"""
import datetime

from django.http import JsonResponse
from django_http_log.common.response import AbstractBaseCodeMessageEnum


class CommonResultEnums:
    SUCCESS = AbstractBaseCodeMessageEnum(code = 20000, message = '请求成功')

    TOKEN_INVALID = AbstractBaseCodeMessageEnum(code = 40001, message = 'accesstoken失效')

    PARAMS_EXCEPTION = AbstractBaseCodeMessageEnum(code = 40002, message = '参数错误')

    PROJECT_EXCEPTION = AbstractBaseCodeMessageEnum(code = 40003, message = '请求头异常')

    RPC_CALL_EXCEPTION = AbstractBaseCodeMessageEnum(code = 40005, message = 'RPC调用异常')

    APPLICATION_NOT_EXIST_BY_APPID = AbstractBaseCodeMessageEnum(code = 40010, message = 'appId不存在')

    APPLICATION_EXIST_BY_APPID = AbstractBaseCodeMessageEnum(code = 40011, message = 'appId已存在')

    APPLICATION_EXIST_BY_APPNAME = AbstractBaseCodeMessageEnum(code = 40012, message = 'appName已存在')

    USER_NOT_EXIST_BY_USERNAME = AbstractBaseCodeMessageEnum(code = 40013, message = '用户名不存在')

    USER_NOT_EXIST_BY_USER_ID = AbstractBaseCodeMessageEnum(code = 40014, message = '用户id不存在')

    CHECK_PASSWORD_FAIL = AbstractBaseCodeMessageEnum(code = 40015, message = '密码错误')

    USERNAME_IS_EXIST = AbstractBaseCodeMessageEnum(code = 40016, message = '用户名已存在')

    PHONE_IS_USED = AbstractBaseCodeMessageEnum(code = 40017, message = '手机号已被使用')

    PERSON_REGISTER_ID_NOT_EXIST = AbstractBaseCodeMessageEnum(code = 40018, message = '注册用户不存在')

    LOG_NOT_EXITS_BY_ID = AbstractBaseCodeMessageEnum(code = 40019, message = '日志id不存在')

    USER_STATUS_IS_FALSE = AbstractBaseCodeMessageEnum(code = 40020, message = '用户状态不合法')

    EMAIL_IS_USED = AbstractBaseCodeMessageEnum(code = 40021, message = '邮箱已被使用')

    MENU_CODE_IS_EXIST = AbstractBaseCodeMessageEnum(code = 40022, message = '菜单code已存在')

    MENU_PARENT_CODE_IS_NOT_EXIST = AbstractBaseCodeMessageEnum(code = 40023, message = '菜单父级code不存在')

    MENU_ID_IS_NOT_EXIST = AbstractBaseCodeMessageEnum(code = 40024, message = '菜单不存在')

    ROLE_NAME_IS_EXIST = AbstractBaseCodeMessageEnum(code = 40025, message = '角色名称已存在')

    ROLE_ID_IS_NOT_EXIST = AbstractBaseCodeMessageEnum(code = 40026, message = '角色id不存在')

    PROJECT_NAME_IS_EXIST = AbstractBaseCodeMessageEnum(code = 40027, message = '项目名称已存在')

    PROJECT_ID_IS_NOT_EXIST = AbstractBaseCodeMessageEnum(code = 40028, message = '项目id不存在')

    DB_TYPE_NOT_EXIST = AbstractBaseCodeMessageEnum(code = 40029, message = '数据库类型不支持')

    DB_ID_IS_NOT_EXIST = AbstractBaseCodeMessageEnum(code = 40030, message = '数据库配置不存在')

    DB_CONNECT_EXCEPTION = AbstractBaseCodeMessageEnum(code = 40031, message = '数据库连接异常')

    DB_TYPE_NOT_SUPPORT = AbstractBaseCodeMessageEnum(code = 40032, message = '数据库类型不支持')

    DB_NAME_IS_EXIST = AbstractBaseCodeMessageEnum(code = 40033, message = '数据库名称已存在')

    CASE_MODULE_ID_IS_NOT_EXIST = AbstractBaseCodeMessageEnum(code = 40034, message = '用例模块不存在')

    CASE_MODULE_NAME_IS_EXIST = AbstractBaseCodeMessageEnum(code = 40035, message = '用例模块名称已存在')

    CASE_MODULE_PARENT_ID_NOT_EXIST = AbstractBaseCodeMessageEnum(code = 40036, message = '用例模块父级id不存在')

    CASE_BASE_ID_IS_NOT_EXIST = AbstractBaseCodeMessageEnum(code = 40037, message = '用例id不存在')
    CASE_IMPORT_ID_IS_NOT_EXIST = AbstractBaseCodeMessageEnum(code = 40038, message = '用例导入importId不存在')

    USER_PROJECT_PERMISSION_IS_FALSE = AbstractBaseCodeMessageEnum(code = 40039, message = '用户项目权限为空，请联系系统管理员')

    MICROSEER_EXCEPTION = AbstractBaseCodeMessageEnum(code = 41001, message = '微知端接口返回错误信息')
    LOCUSTS_PROCESS_STARTING = AbstractBaseCodeMessageEnum(code = 41002, message = '压测资源池已被占用，请稍后重试')
    LOCUSTS_PROCESS_NOT_STARTING = AbstractBaseCodeMessageEnum(code = 41003, message = '没有正在进行的性能测试资源')
    LOCUSTS_PROCESS_UUID_IS_EXIST = AbstractBaseCodeMessageEnum(code = 41004, message = '当前进程不存在')

    SYSTEM_EXCEPTION = AbstractBaseCodeMessageEnum(code = 50000, message = '系统异常')

    PIONEER_BASE_EXCEPTION = AbstractBaseCodeMessageEnum(code = 50001, message = '内部错误')


class PioneerBaseExceptionResponse:
    def __new__(cls, message: str, code=50001, result=None):
        return JsonResponse(
            data = dict(
                code = code,
                message = message,
                result = result,
                systemTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
                type = 'success'
            ),
            json_dumps_params = {"ensure_ascii": False}
        )


def get_status_code():
    status_code = []
    for i in CommonResultEnums().__dir__():
        if i[0:2] != '__':
            code = eval(f'CommonResultEnums.{i}.code')
            message = eval(f'CommonResultEnums.{i}.message')
            status_code.append(dict(code = code, message = message))

    return status_code
